package com.haven123.cloudapp.rabbitmq.send;

import com.haven123.cloudapp.rabbitmq.Config.ExchangeConfig;
import com.haven123.cloudapp.rabbitmq.demo.AnnotionListener;
import com.haven123.cloudapp.rabbitmq.demo.CodeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author haven
 */
@Slf4j
@EnableScheduling
@Component
public class Sender {

    private  volatile int i=0;
    private  int j=0;
    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void connectTestSend(int i){
       rabbitTemplate.convertAndSend(AnnotionListener.exchange_name,AnnotionListener.routingKey_name,"hello i am sender;"+i);
    }
    public void connectTest2Send(int i){
       rabbitTemplate.convertAndSend(CodeListener.exchange_name,CodeListener.routingKey_name,"hello i am sender;"+i);
    }
    @Scheduled(fixedDelay = 10000)
    public void testSend(){
        rabbitTemplate.convertAndSend(ExchangeConfig.direct_name, "one","这里发送direct交换机使用one  routingkey  j:"+j);
        rabbitTemplate.convertAndSend(ExchangeConfig.direct_name, "two","这里发送direct交换机使用two  routingkey  j:"+j);
        rabbitTemplate.convertAndSend(ExchangeConfig.fanout_name, "three","这里发送fanout交换机使用three  routingkey  j:"+j);
        rabbitTemplate.convertAndSend(ExchangeConfig.topic_name, "*.four.tipic.*","这里发送topic交换机使用*.four.tipic  routingkey  j:"+j);
        j++;
    }
    @Scheduled(fixedDelay = 1000)
    public void testSendAdd(){
        rabbitTemplate.convertAndSend(ExchangeConfig.direct_name, "seven","这里发送direct交换机使用one 测试多个监听一个顺序 routingkey  i:"+i);
        i++;
        log.info("发送的是i:"+i);
    }
}
